import config from "@/config";
import http from "@/utils/request";

export default {
	// 库存

	// 仓库管理
	getWarehouseList: {
		url: `${config.API_URL}/warehouse/list`,
		name: "获取仓库列表",
		get: async function (data = {}) {
			return new Promise((resolve, reject) => {
				http.get(this.url, data)
					.then((response) => {
						resolve(response);
					})
					.catch((error) => {
						resolve(error.data);
					});
			});
		},
	},

	getWarehouseDetailById: {
		url: `${config.API_URL}/warehouse/detailById`,
		name: "根据ID获取仓库详情",
		post: async function (data = {}) {
			return new Promise((resolve, reject) => {
				http.postParam(this.url, data)
					.then((response) => {
						resolve(response);
					})
					.catch((error) => {
						resolve(error.data);
					});
			});
		},
	},

	addWarehouse: {
		url: `${config.API_URL}/warehouse/add`,
		name: "添加仓库",
		post: async function (data = {}) {
			return new Promise((resolve, reject) => {
				http.post(this.url, data)
					.then((response) => {
						resolve(response);
					})
					.catch((error) => {
						resolve(error.data);
					});
			});
		},
	},

	updateWarehouse: {
		url: `${config.API_URL}/warehouse/update`,
		name: "修改仓库",
		post: async function (data = {}) {
			return new Promise((resolve, reject) => {
				http.post(this.url, data)
					.then((response) => {
						resolve(response);
					})
					.catch((error) => {
						resolve(error.data);
					});
			});
		},
	},

	// 库存管理
	getStockList: {
		url: `${config.API_URL}/stock/list`,
		name: "获取库存列表",
		get: async function (data = {}) {
			return new Promise((resolve, reject) => {
				http.get(this.url, data)
					.then((response) => {
						resolve(response);
					})
					.catch((error) => {
						resolve(error.data);
					});
			});
		},
	},

	addStock: {
		url: `${config.API_URL}/stock/add`,
		name: "添加库存",
		post: async function (data = {}) {
			return new Promise((resolve, reject) => {
				http.post(this.url, data)
					.then((response) => {
						resolve(response);
					})
					.catch((error) => {
						resolve(error.data);
					});
			});
		},
	},

	updateStock: {
		url: `${config.API_URL}/stock/update`,
		name: "修改库存",
		post: async function (data = {}) {
			return new Promise((resolve, reject) => {
				http.post(this.url, data)
					.then((response) => {
						resolve(response);
					})
					.catch((error) => {
						resolve(error.data);
					});
			});
		},
	},

	//领用管理 类型：1领用2报废3归还4借用
	getReceiveList: {
		url: `${config.API_URL}/warehouseClaim/list`,
		name: "获取领用列表",
		get: async function (data = {}) {
			return new Promise((resolve, reject) => {
				http.get(this.url, data)
					.then((response) => {
						resolve(response);
					})
					.catch((error) => {
						resolve(error.data);
					});
			});
		},
	},

	addReceive: {
		url: `${config.API_URL}/warehouseClaim/add`,
		name: "添加领用",
		post: async function (data = {}) {
			return new Promise((resolve, reject) => {
				http.post(this.url, data)
					.then((response) => {
						resolve(response);
					})
					.catch((error) => {
						resolve(error.data);
					});
			});
		},
	},

	updateReceive: {
		url: `${config.API_URL}/warehouseClaim/update`,
		name: "编辑领用",
		post: async function (data = {}) {
			return new Promise((resolve, reject) => {
				http.post(this.url, data)
					.then((response) => {
						resolve(response);
					})
					.catch((error) => {
						resolve(error.data);
					});
			});
		},
	},

	deleteReceive: {
		url: `${config.API_URL}/warehouseClaim/delete`,
		name: "删除领用",
		post: async function (data = {}) {
			return new Promise((resolve, reject) => {
				http.postParam(this.url, data)
					.then((response) => {
						resolve(response);
					})
					.catch((error) => {
						resolve(error.data);
					});
			});
		},
	},

	// 出入库管理
	getInoutList: {
		url: `${config.API_URL}/warehouseInout/inoutList`,
		name: "获取出入库管理",
		get: async function (data = {}) {
			return new Promise((resolve, reject) => {
				http.get(this.url, data)
					.then((response) => {
						resolve(response);
					})
					.catch((error) => {
						resolve(error.data);
					});
			});
		},
	},

	confirmInout: {
		url: `${config.API_URL}/warehouseInout/confirmInout`,
		name: "确认出入库",
		post: async function (data = {}) {
			return new Promise((resolve, reject) => {
				http.postParam(this.url, data)
					.then((response) => {
						resolve(response);
					})
					.catch((error) => {
						resolve(error.data);
					});
			});
		},
	},

	updateInout: {
		url: `${config.API_URL}/warehouseInout/updateInout`,
		name: "修改出入库数量（实际数量）",
		post: async function (data = {}) {
			return new Promise((resolve, reject) => {
				http.post(this.url, data)
					.then((response) => {
						resolve(response);
					})
					.catch((error) => {
						resolve(error.data);
					});
			});
		},
	},

	// 调拨管理
	getAllotList: {
		url: `${config.API_URL}/allocate/list`,
		name: "获取调拨列表",
		get: async function (data = {}) {
			return new Promise((resolve, reject) => {
				http.get(this.url, data)
					.then((response) => {
						resolve(response);
					})
					.catch((error) => {
						resolve(error.data);
					});
			});
		},
	},

	addAllot: {
		url: `${config.API_URL}/allocate/add`,
		name: "添加调拨",
		post: async function (data = {}) {
			return new Promise((resolve, reject) => {
				http.post(this.url, data)
					.then((response) => {
						resolve(response);
					})
					.catch((error) => {
						resolve(error.data);
					});
			});
		},
	},

	updateAllot: {
		url: `${config.API_URL}/allocate/update`,
		name: "修改调拨",
		post: async function (data = {}) {
			return new Promise((resolve, reject) => {
				http.post(this.url, data)
					.then((response) => {
						resolve(response);
					})
					.catch((error) => {
						resolve(error.data);
					});
			});
		},
	},
};
